home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
rjs.lha
/
RJS
/
Transport
/
src
/
InetSocket.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-06-14
|
2KB
|
89 lines
#include <stdio.h>
#include <osfcn.h>
#include <libc.h>
#include <errno.h>
#include <string.h>
#include <netdb.h>
#include <iostream.h>
#include "Transport.h"
#include <RJS/Util.h>
extern "C" {
unsigned long htonl(unsigned long);
unsigned short htons(unsigned short);
struct hostent *gethostbyname(const char *host);
}
int RJS_InetSocket::connect(const RJS_InetAddress &ia)
{
return RJS_Socket::connect(ia,ia.size());
}
int RJS_InetSocket::bind(const RJS_InetAddress &ia)
{
return RJS_Socket::bind(ia,ia.size());
}
int RJS_InetSocket::getpeername(RJS_InetAddress &ia)
{
ia.addrlen=ia.size();
int stat=RJS_Socket::getpeername(ia,ia.addrlen);
if (stat) ia.ss_set(RJS_InetAddress::HostFound);
else ia.ss_set(RJS_InetAddress::UnknownHost);
return stat;
}
int RJS_InetSocket::getsockname(RJS_InetAddress &ia)
{
ia.addrlen=ia.size();
int stat=RJS_Socket::getsockname(ia,ia.addrlen);
if (stat) ia.ss_set(RJS_InetAddress::HostFound);
else ia.ss_set(RJS_InetAddress::UnknownHost);
return stat;
}
int RJS_InetSocket::accept(RJS_InetSocket &newsocket)
{
if (!ok() || !is_passive()) {
newsocket.td = -1;
newsocket.ss_set(SS_error);
return 0;
}
if (newsocket.inuse()) newsocket.close();
newsocket = *this; // copy current socket
RJS_InetAddress remote;
remote.addrlen=remote.size();
newsocket.td = RJS_Socket::accept(remote,remote.addrlen);
if (newsocket.td < 0 ) {
newsocket.ss_set(RJS_Status(errno));
if (return_on_error) return 0;
RJS_Util::crash_and_burn("RJS_InetSocket","accept",ss_message());
} else {
newsocket.ss_set(SS_success);
return 1;
}
}
int RJS_InetSocket::recvfrom(char *buffer,int maxbuf, RJS_InetAddress &ia)
{
ia.addrlen=ia.size();
int stat=RJS_Socket::recvfrom(buffer,maxbuf,ia,ia.addrlen);
if (stat) ia.ss_set(RJS_InetAddress::HostFound);
else ia.ss_set(RJS_InetAddress::NoHostGiven);
return stat;
}
int RJS_InetSocket::sendto(char *buffer,int len,const RJS_InetAddress &ia)
{
return RJS_Socket::sendto(buffer,len,ia,ia.addrlen);
}